﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_Public;
using QLTV_BLL;

namespace QLTV_GiaoDien
{
    public partial class uc_NhaXuatBan : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_NhaXuatBan()
        {
            InitializeComponent();
        }
        public void GetLoad(int kt)
        {
            txt_Load.Text = kt.ToString();
        }
        NhaXuatBan_BLL nxb_bll = new NhaXuatBan_BLL();
        private void uc_NhaXuatBan_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = nxb_bll.LayDuLieu();
            txt_Load.Hide();
        }
        private void bbi_Them_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_NhaXuatBan f = new frm_NhaXuatBan();
            f.Flag = 0;
            f.MyGetData = new frm_NhaXuatBan.GetInt(GetLoad);
            f.ShowDialog();
            
        }

        private void bbi_Sua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_NhaXuatBan f = new frm_NhaXuatBan();
            f.Flag = 1;
            f.MyGetData = new frm_NhaXuatBan.GetInt(GetLoad);
            f.MaNhaXuatBan = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Nhà Xuất Bản"));
            f.TenNhaXuatBan = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Nhà Xuất Bản").ToString();
            f.DiaChi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Địa Chỉ").ToString();
            f.SoDienThoai = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Số Điện Thoại").ToString();
            f.Fax = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Fax").ToString();
            f.Email = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Email").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }

        private void bbi_Xem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_NhaXuatBan f = new frm_NhaXuatBan();
            f.Flag = 2;
            f.MyGetData = new frm_NhaXuatBan.GetInt(GetLoad);
            f.MaNhaXuatBan = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Nhà Xuất Bản"));
            f.TenNhaXuatBan = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Nhà Xuất Bản").ToString();
            f.DiaChi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Địa Chỉ").ToString();
            f.SoDienThoai = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Số Điện Thoại").ToString();
            f.Fax = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Fax").ToString();
            f.Email = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Email").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            frm_NhaXuatBan f = new frm_NhaXuatBan();
            f.Flag = 2;
            f.MyGetData = new frm_NhaXuatBan.GetInt(GetLoad);
            f.MaNhaXuatBan = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Nhà Xuất Bản"));
            f.TenNhaXuatBan = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Nhà Xuất Bản").ToString();
            f.DiaChi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Địa Chỉ").ToString();
            f.SoDienThoai = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Số Điện Thoại").ToString();
            f.Fax = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Fax").ToString();
            f.Email = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Email").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }

        NhatKy_BLL nhatKy_bll = new NhatKy_BLL();
        NhatKy_Public nk = new NhatKy_Public();
        TrungGian tg = new TrungGian();
        private void bbi_Xoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            NhaXuatBan_Public nxb = new NhaXuatBan_Public();
            nxb.MaNhaXuatBan =Convert.ToInt32( gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Mã Nhà Xuất Bản").ToString());
            nxb.TenNhaXuatBan =gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Nhà Xuất Bản").ToString();
            if (XtraMessageBox.Show("Bạn có muốn xóa Nhà xuất bản: '" + nxb.TenNhaXuatBan + "' có mã là: '" + nxb.MaNhaXuatBan + "'", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                nxb_bll.delete_nhaXuatBan(nxb);
                //
                string d = DateTime.Now.ToString();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Xóa";
                nk.MoTa = "Sửa thông tin Nhà xuất bản: '" +nxb.TenNhaXuatBan + "'";
                nhatKy_bll.insert_nhatKy(nk, nk, nk, nk);
                //
                uc_NhaXuatBan_Load(sender,e);
            }
        }

        private void bbi_Refresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            uc_NhaXuatBan_Load(sender,e);
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                uc_NhaXuatBan_Load(sender,e);
                txt_Load.Text = "0";
            }
        }


    }
}
